package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.PaymentPlan;
import cn.gson.springboot.model.pojos.PaymentRecords;
import cn.gson.springboot.model.service.PaymentRecordsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PaymentRecordsController {
    @Autowired
    PaymentRecordsService payRecordsService;

    @RequestMapping("/pay-records-list")
    @ResponseBody
    public Map<String,Object> payRecordsList(Integer page, Integer size, Integer value,Integer num,String payDate){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<PaymentRecords> pay = payRecordsService.selectPaymentRecords(value,num,payDate);
        Map<String,Object> map = new HashMap<>();
        map.put("total",objects.getTotal());
        map.put("rows",pay);
        return map;
    }

    @RequestMapping("/pay-records-pur-list")
    @ResponseBody
    public List<PaymentRecords>payRecordsDateList(Integer purId){
        List<PaymentRecords> pay = payRecordsService.selectPaymentRecordsByPurId(purId);
        return pay;
    }

    @RequestMapping("/pay-records-month-list")
    @ResponseBody
    public List<PaymentRecords> selectPaymentRecordsMonth(){
        List<PaymentRecords> pay = payRecordsService.selectPaymentRecordsMonth();
        return pay;
    }

    @RequestMapping("/pay-records")
    @ResponseBody
    public PaymentRecords paymentRecords(Integer payId){
        PaymentRecords pay = payRecordsService.selectPaymentRecordsById(payId);
        return pay;
    }

    @PostMapping("/save-pay-records")
    @ResponseBody
    public void savePaymentRecords(@RequestBody PaymentRecords pay){
        payRecordsService.savePaymentRecords(pay);
    }

    @PostMapping("/delete-pay-records")
    @ResponseBody
    public void deletePaymentRecords(@RequestParam(value = "payId") Integer payId){
        payRecordsService.deletePaymentRecords(payId);
    }

}
